package com.lazydong.apiforward.jpackage;

import com.lazydong.apiforward.jpackage.enums.BatEnum;
import com.lazydong.apiforward.jpackage.enums.ModuleEnum;
import com.lazydong.apiforward.jpackage.util.PackageUtil;

import java.io.File;
import java.util.Scanner;

/**
 * 打包工具
 */
public class ApiForwardPackage {
    public static void main(String[] args) {
        ApiForwardPackage apiForwardPackage = new ApiForwardPackage();
        apiForwardPackage.run();
    }


    public void run() {
        ModuleEnum[] moduleEnums = ModuleEnum.values();
        for (int i = 0; i < moduleEnums.length; i++) {
            System.out.println(i + "、" + moduleEnums[i].name());
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择要打包的模块的序号：");
        int nexted = scanner.nextInt();
        if (nexted < moduleEnums.length) {
            ModuleEnum moduleEnum = moduleEnums[nexted];
            // 生成临时脚本
            jPackage(moduleEnum);
            return;
        }
        throw new RuntimeException("请正确选择序号");
    }


    private static void jPackage(ModuleEnum moduleEnum) {
        String buildDirectory = System.getProperty("user.dir") + File.separator + moduleEnum.moduleName + File.separator + "target";
        PackageUtil.runBat(BatEnum.MVN_CLEAN_PACKAGE, moduleEnum);

        PackageUtil.copyFile(moduleEnum, buildDirectory);

        PackageUtil.runBat(BatEnum.J_PACKAGE, moduleEnum);

        System.out.println("开始压缩文件");
        PackageUtil.zipExe(moduleEnum);
        System.out.println("打包完成，Zip包：" + moduleEnum.zipName);
    }
}
